package com.yunkaweilai.android.view.popup;

import android.app.Activity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.animation.Animation;
import android.widget.ImageView;
import android.widget.LinearLayout;

import com.yunkaweilai.android.R;
import com.yunkaweilai.android.net.Glide.GlideUtils;
import com.yunkaweilai.android.view.OvalImageView;

import razerdp.basepopup.BasePopupWindow;

/**
 * 图片放大
 * Created by Administrator on 2017/7/17.
 */

public class ImageEnlagePopup extends BasePopupWindow {

    private View popupView;
    private Activity mContext;
    private ImageView idImgClose;
    private OvalImageView idLargeImg;
    private String url;
    private int error;
    private LinearLayout idRlayoutImgBg;

    public ImageEnlagePopup(Activity context, String url, int error) {
        super(context);
        this.mContext = context;
        this.url = url;
        this.error = error;
        bindEvent();
    }


    @Override
    protected Animation initShowAnimation() {
        return getTranslateAnimation(250 * 2, 0, 300);
    }

    @Override
    public View getClickToDismissView() {
        return popupView.findViewById(R.id.id_rlayout_all);
    }

    @Override
    public View onCreatePopupView() {
        popupView = LayoutInflater.from(getContext()).inflate(R.layout.popup_image_enlage, null);
        return popupView;
    }

    @Override
    public View initAnimaView() {
        return popupView.findViewById(R.id.id_rlayout_bottom);
    }

    private void bindEvent() {
        if (popupView != null) {
            initView();
//            int[] deviceInfo = DensityUtil.getDeviceInfo(mContext);
//            int mywidth = deviceInfo[0] - 40;
//            RelativeLayout.LayoutParams layoutParams = (RelativeLayout.LayoutParams) idRlayoutImgBg.getLayoutParams();
//            layoutParams.height = mywidth;
//            idRlayoutImgBg.setLayoutParams(layoutParams);

            GlideUtils.loadImage(mContext, url, idLargeImg, error);
            idImgClose.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    dismiss();
                }
            });

        }
    }


    private void initView() {
        idImgClose = ((ImageView) popupView.findViewById(R.id.id_img_close));
        idLargeImg = ((OvalImageView) popupView.findViewById(R.id.id_large_img));
        idRlayoutImgBg = ((LinearLayout) popupView.findViewById(R.id.id_rlayout_img_bg));
    }
}
